package com.happyscan138.makefun.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.happyscan138.makefun.BaseAdapter.systemNews_listview;
import com.happyscan138.makefun.R;
import com.happyscan138.makefun.View.RoundImageView;

import java.util.List;

/**
 * Created by Administrator on 2016/12/20.
 */

public class systemNewsAdapter extends BaseAdapter {
    public systemNewsAdapter(Context mContext, List<systemNews_listview> mdata) {
        this.mContext = mContext;
        this.mdata = mdata;
    }

    private Context mContext;
    private List<systemNews_listview> mdata;

    @Override
    public int getCount() {
        return mdata.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder_systemNews viewHolder;
        //判断converView是否为空
        if(convertView==null){
            viewHolder=new ViewHolder_systemNews();
            convertView=View.inflate(mContext, R.layout.system_news_item,null);
            viewHolder.systemNews_head=(RoundImageView) convertView.findViewById(R.id.system_news_head);
            viewHolder.systemNews_name=(TextView) convertView.findViewById(R.id.system_news_name);

            //将viewHolder与converView绑定
            convertView.setTag(viewHolder);
        }else {
            //如果存在converView，取出保存在converView中的viewHolder
            viewHolder=(ViewHolder_systemNews) convertView.getTag();
        }
        systemNews_listview bean=mdata.get(position);
        //通过viewHolder找到对应控件，避免每次通过findViewById找控件

        viewHolder.systemNews_name.setText(bean.text);
        return convertView;
    }
}
class ViewHolder_systemNews{
    public RoundImageView systemNews_head;
    public TextView systemNews_name;

}